<template>
  <div>
    <!-- <div class="toptitle">组织编码</div> -->
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      @keyup.enter.native="search()"
    >
      <!-- <el-form-item label="问卷识别码">
                <el-input v-model="formInline.questionnaireNo" placeholder></el-input>
            </el-form-item> -->
      <el-form-item label="会员编号">
        <br />
        <br />
        <el-input
          v-model="formInline.memberSeq"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>

      <el-form-item label="会员昵称">
        <br />
        <br />
        <el-input
          v-model="formInline.nickName"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="会员手机号">
        <br />
        <br />
        <el-input
          v-model="formInline.cellPhoneNo"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="店铺名称">
        <br />
        <br />
        <el-input
          v-model="formInline.storeName"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="关联订单号">
        <br />
        <br />
        <el-input
          v-model="formInline.orderNo"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>
      <br />
      <el-form-item label="店铺授权编码">
        <br />
        <br />
        <el-input
          v-model="formInline.authCode"
          placeholder
          style="margin-left: -80px; width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="大区名称">
        <br />
        <br />
        <el-input
          v-model="formInline.upOrgZone"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="营销区域名称">
        <br />
        <br />
        <el-input
          v-model="formInline.baseName"
          placeholder
          style="margin-left: -60px; width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="会员等级">
        <br />
        <br />
        <el-select
          v-model="formInline.gradeLevel"
          placeholder="全部"
          clearable
          style="margin-left: -60px; width: 200px"
        >
          <el-option
            v-for="(send, i) in options"
            :key="i"
            :value="send.uuid"
            :label="send.gradelevelName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item style="margin-left: 700px; text-align: right">
        <el-button
          type="primary"
          @click="search()"
          size="mini"
          icon="el-icon-search"
          >查询</el-button
        >
        <!-- </el-form-item>
            <el-form-item> -->
        <el-button
          type="primary"
          @click="kong()"
          size="mini"
          icon="el-icon-delete"
          >清空</el-button
        >
        <!-- </el-form-item>
 <el-form-item> -->
        <el-button
          type="success"
          @click="exportExcel()"
          size="mini"
          icon="el-icon-s-data"
          >导出</el-button
        >
        <!-- </el-form-item>
           <el-form-item> -->
        <el-button
          type="primary"
          @click="creatoneOrg()"
          size="mini"
          icon="el-icon-edit"
          >选项统计</el-button
        >
        <!-- </el-form-item>
             <el-form-item> -->
        <el-button type="primary" @click="goback()" size="mini">返回</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      style="width: 100%; margin-bottom: 20px"
      row-key="goodsTypeId"
      border
      v-loading="loading"
      default-expand-all
      @sort-change="handleSort"
    >
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="60"
      ></el-table-column>
      <el-table-column
        prop="memberSeq"
        label="会员编号"
        width="180"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="nickName"
        label="会员昵称"
        align="center"
        width="120"
      ></el-table-column>
      <el-table-column prop="gradelevelName" label="会员等级">
      </el-table-column>
      <el-table-column
        prop="cellPhoneNo"
        label="会员手机号码"
        align="center"
        width="180"
      ></el-table-column>

      <el-table-column
        prop="orderNo"
        label="关联订单号"
        align="center"
        width="120"
      ></el-table-column>

      <el-table-column
        prop="orderMoney"
        label="订单金额"
        width="180"
        sortable="orderMoney"
        align="center"
      >
      </el-table-column>

      <el-table-column
        prop="orderGoods"
        label="商品名称"
        align="center"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="satisfaction"
        label="消费者满意度"
        width="180"
        sortable="satisfaction"
        align="center"
        :formatter="fixData"
      ></el-table-column>

      <el-table-column
        prop="optionName"
        label="用户反馈"
        align="center"
        width="120"
      ></el-table-column>

      <el-table-column
        prop="storeName"
        label="店铺名称"
        align="center"
        width="180"
      ></el-table-column>

      <el-table-column
        prop="authCode"
        label="店铺授权编码"
        align="center"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="upOrgZone"
        label="大区名称"
        align="center"
        width="180"
      ></el-table-column>

      <el-table-column
        prop="baseName"
        label="营销区域名称"
        align="center"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="updateTime"
        label="提交时间"
        align="center"
        width="180"
      ></el-table-column>

      <el-table-column label="操作" width="280" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="changeorg(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-form :inline="true" :model="formInline">
      <el-form-item style="margin-top: 6px"></el-form-item>
    </el-form>
    <div class="block" style="margin-top: -49px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30, 50, 100, 150, 200]"
        :current-page="listQuery.current"
        :page-size="listQuery.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <!--添加-->
    <el-dialog title="" :visible.sync="dialogVisibleorg" width="50%">
      <el-table
        :data="tableDatawenti"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        style="width: 100%; margin-bottom: 20px"
        row-key="goodsTypeId"
        border
        v-loading="loading"
        default-expand-all
      >
        <el-table-column
          prop="subjectName"
          label="问题"
          align="center"
        ></el-table-column>

        <el-table-column
          prop="optionName"
          label="所选答案"
          align="center"
        ></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleorg = false" size="mini"
          >取 消</el-button
        >
        <el-button type="primary" @click="confirmEditone()" size="mini"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog title="" :visible.sync="dialogVisibleorgtwo" width="50%">
      <div v-for="(item, i) in this.tableDatatongji" style="margin-top: 60px">
        <span
          style="margin-bottom:20px;display:inline-block；color:#000;font-size:17px"
          v-if="tableDatatongji[i].optionDTOS"
          >{{ item.subjectName }}</span
        >
        <el-table
          :data="tableDatatongji[i].optionDTOS"
          :header-cell-style="{
            background: '#eef1f6',
            color: '#606266',
          }"
          style="width: 100%; margin-bottom: 30px; margin-top: 20px"
          row-key="goodsTypeId"
          border
          v-loading="loading"
          default-expand-all
          v-if="tableDatatongji[i].optionDTOS"
        >
          <el-table-column
            prop="optionName"
            :label="
              item.subjectType == 0
                ? '单选题'
                : item.subjectType == 1
                ? '多选题'
                : '评分题'
            "
            align="center"
          ></el-table-column>

          <el-table-column
            prop="count"
            label="小计"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="proportion"
            label="比例"
            align="center"
          ></el-table-column>
          <div slot="append" style="margin-left: 80px">
            <div class="sum_footer xiaoji" ref="sum_xiaoji">
              <div class="sum_footer_unit center">
                填写人数（人）：<span>{{
                  tableDatatongji[i].optionDTOS[0].total
                }}</span>
              </div>
              <!-- <div class='sum_footer_unit' style="di">{{total}}</div> -->
            </div>
          </div>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleorgtwo = false" size="mini"
          >取 消</el-button
        >
      </span>
    </el-dialog>
    <!--修改-->
    <el-dialog title="" :visible.sync="dialogVisibleorgone" width="50%">
      <el-form
        :model="ruleFormorg"
        :rules="rules"
        ref="ruleFormorg"
        label-width="120px"
      >
        <el-form
          :model="ruleFormorg"
          :rules="rules"
          ref="ruleFormorg"
          label-width="120px"
        >
          <el-form-item label="分类名称" prop="goodsTypeName">
            <el-input
              v-model="ruleFormorg.goodsTypeName"
              maxlength="20"
            ></el-input>
          </el-form-item>
          <el-form-item label="是否关联活动" prop="isRelatedActivity">
            <el-radio-group v-model="ruleFormorg.isRelatedActivity" size="mini">
              <el-radio-button label="0">否</el-radio-button>
              <el-radio-button label="1">是</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="展示顺序" prop="sortNo">
            <el-input
              v-model="ruleFormorg.sortNo"
              type="number"
              :min="this.total + 1"
              @change="
                (data) => {
                  ruleFormorg.sortNo = checkSortNo(data);
                }
              "
            ></el-input>
          </el-form-item>
          <el-form-item label="是否展示" prop="isDisplay">
            <el-select v-model="ruleFormorg.isDisplay">
              <el-option label="不展示" :value="0"></el-option>
              <el-option label="展示" :value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="展示形式" prop="displayForm">
            <el-select v-model="ruleFormorg.displayForm">
              <el-option label="单个陈列" :value="1"></el-option>
              <el-option label="两个陈列" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="分类图标:" prop="tagUrl">
                        <el-row>
                            <el-col style="margin: 10px; 0px; 10px; 0">
                                <el-upload
                                    style="margin: 10px;"
                                    :action="action"
                                    list-type="picture-card"
                                    :limit="1"
                                    :on-preview="handlePictureCardPreview"
                                    :on-success="upLoadPicone"
                                    :on-change="handleImgChangeone"
                                    :file-list="imgListone"
                                    :headers="headers"
                                    :on-exceed="handleExceed"
                                >
                                    <i class="el-icon-plus"></i>
                                </el-upload>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="分类照片:" prop="picUrl">
                        <el-row>
                            <el-col style="margin: 10px; 0px; 10px; 0">
                                <el-upload
                                    style="margin: 10px;"
                                    :action="action"
                                    list-type="picture-card"
                                    :limit="1"
                                    :on-preview="handlePictureCardPreview"
                                    :on-success="upLoadPictwo"
                                    :on-change="handleImgChangetwo"
                                    :file-list="imgListtwo"
                                    :headers="headers"
                                    :on-exceed="handleExceed"
                                >
                                    <i class="el-icon-plus"></i>
                                </el-upload>
                            </el-col>
                        </el-row>
                    </el-form-item>-->
        </el-form>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleorgone = false" size="mini"
          >取 消</el-button
        >
        <el-button type="primary" @click="confirmEdittwo()" size="mini"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisibleImg">
      <img width="100%" :src="dialogImageUrl" alt />
    </el-dialog>
  </div>
</template>

<script>
import {
  queryQuestionnaireList,
  queryQuestionnaireListExcel,
  queryQuestionnaireInfoById,
  queryOptionStatistics,
} from '@/api/questionnaireStatistical';
import Sortable from 'sortablejs';
import { getmemberrule } from '@/api/membergrade';
import qs from 'qs';
export default {
  data() {
    return {
      action: `${process.env.VUE_APP_BASE_API}/api/file-service/v1/file/uploadFile`,
      headers: {
        token: localStorage.getItem('token'), //从cookie里获取token，并赋值  Authorization ，而不是token
      },
      options: [],
      titlename: '',
      tableDatatongji: [],
      tableData: [],
      tableDatawenti: [],
      txtVal: '',
      picUrl: '',
      dialogVisibleorgtwo: false,
      loading: true,
      dialogVisibleorg: false,
      dialogVisibleorgone: false,
      imgListone: [],
      imgListtwo: [],
      questionnaireId: '1',
      ruleForm: {
        goodsTypeId: '',
        goodsTypeName: '',
        isRelatedActivity: 0,
        sortNo: 0,
        tagUrl: '',
        picUrl: '',
        isDisplay: 1,
        displayForm: 1,
        goodsTypeId: '',
        upGoodsType: '',
      },
      orgSeqxia: '',
      ruleFormorg: {
        goodsTypeId: '',
        goodsTypeName: '',
        isRelatedActivity: 0,
        sortNo: 0,
        tagUrl: '',
        picUrl: '',
        isDisplay: 1,
        displayForm: 1,
        goodsTypeId: '',
        upGoodsType: '',
      },
      total: 0,
      options: [],
      optionsone: [],
      listQuery: {
        current: 1,
        size: 100,
      },
      flagorg: false,
      dialogVisible: false,
      dialogVisibleImg: false,
      dialogImageUrl: '',
      formInline: {
        questionnaireNo: '',
        memberSeq: '',
        gradeLevel: '',
        gradeLevel: '',
        nickName: '',
        cellPhoneNo: '',
        storeName: '',
        orderNo: '',
        authCode: '',
        upOrgZone: '',
        baseName: '',
        moneySort: '',
        satisfactionSort: '',
      },
      rules: {
        goodsTypeName: [
          {
            required: true,
            message: '请输入商品名称',
            trigger: 'blur',
          },
        ],
        // tagUrl: [
        //     { required: true, message: "请上传图标", trigger: "blur" }
        // ],
        // picUrl: [
        //     { required: true, message: "请上传图片", trigger: "blur" }
        // ]
      },
    };
  },
  mounted() {
    var v = this.$route.params.uuid;
    if (v) {
      this.questionnaireId = v;
    }
    this.rolemanageone();
    this._getmemberinfo();
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    fixData(row, column, cellValue, index) {
      if (cellValue != null && !isNaN(cellValue)) {
        return cellValue + '%';
      } else {
        return cellValue;
      }
    },
    // getSummaries(param) {
    //   const { columns, data } = param;
    //   const sums = [];
    //   columns.forEach((column, index) => {
    //     if (index === 0) {
    //       sums[index] = '填写人数';
    //       return;
    //     }
    //     const values = data.map(item => Number(item[column.count]));

    //   });

    //   return sums;
    // },
    //初始化加载
    exportExcel() {
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          questionnaireId: this.questionnaireId,
          questionnaireNo: this.formInline.questionnaireNo,
          memberSeq: this.formInline.memberSeq,
          gradeLevel: this.formInline.gradeLevel,
          gradeLevel: this.formInline.gradeLevel,
          nickName: this.formInline.nickName,

          cellPhoneNo: this.formInline.cellPhoneNo,
          storeName: this.formInline.storeName,
          orderNo: this.formInline.orderNo,
          authCode: this.formInline.authCode,
          upOrgZone: this.formInline.upOrgZone,
          baseName: this.formInline.baseName,
        },
        ascs: [],
        descs: [],
      };
      queryQuestionnaireListExcel(data)
        .then((res) => {
          const link = document.createElement('a');
          let blob = new Blob([res], {
            type: 'application/vnd.ms-excel',
          });
          link.style.display = 'none';
          //设置连接
          link.href = URL.createObjectURL(blob);
          link.download = '问卷数据统计列表.xlsx';
          document.body.appendChild(link);
          //模拟点击事件
          link.click();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    _getmemberinfo() {
      let data = {
        size: 99,
        current: 1,
        condition: {},
        ascs: [],
        descs: [],
      };
      getmemberrule(data).then((res) => {
        this.options = res.records;
      });
    },
    rolemanageone() {
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          questionnaireId: this.questionnaireId,
          questionnaireNo: this.formInline.questionnaireNo,
          memberSeq: this.formInline.memberSeq,
          gradeLevel: this.formInline.gradeLevel,
          gradeLevel: this.formInline.gradeLevel,
          nickName: this.formInline.nickName,

          cellPhoneNo: this.formInline.cellPhoneNo,
          storeName: this.formInline.storeName,
          orderNo: this.formInline.orderNo,
          authCode: this.formInline.authCode,
          upOrgZone: this.formInline.upOrgZone,
          baseName: this.formInline.baseName,
        },
      };
      queryQuestionnaireList(data).then((res) => {
        res.records.forEach((item, i) => {
          this.options.push({
            value: item.goodsTypeId,
            label: item.orgName,
          });
        });

        this.loading = false;
        this.total = res.total;
        this.tableData = res.records;
        console.log(this.tableData, 'ppe');
      });

      //   let dataone = {
      //     orgType: "",
      //     orgTypeName: ""
      //   };

      //   getUserOrgType(dataone).then(res => {
      //     res.records.forEach((item, i) => {
      //       this.optionsone.push({
      //         value: item.orgType,
      //         label: item.orgTypeName
      //       });
      //     });
      //   });
    },
    //清空
    kong() {
      this.formInline.questionnaireNo = '';
      this.formInline.memberSeq = '';
      this.formInline.gradeLevel = '';
      (this.formInline.gradeLevel = ''), (this.formInline.nickName = '');
      this.formInline.cellPhoneNo = '';
      this.formInline.storeName = '';
      this.formInline.orderNo = '';
      this.formInline.authCode = '';

      this.formInline.upOrgZone = '';
      this.formInline.baseName = '';
    },
    //查询
    search() {
      this.listQuery.current = 1;
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          questionnaireId: this.questionnaireId,
          questionnaireNo: this.formInline.questionnaireNo,
          memberSeq: this.formInline.memberSeq,
          gradeLevel: this.formInline.gradeLevel,
          gradeLevel: this.formInline.gradeLevel,
          nickName: this.formInline.nickName,

          cellPhoneNo: this.formInline.cellPhoneNo,
          storeName: this.formInline.storeName,
          orderNo: this.formInline.orderNo,
          authCode: this.formInline.authCode,
          upOrgZone: this.formInline.upOrgZone,
          baseName: this.formInline.baseName,
        },
      };
      queryQuestionnaireList(data).then((res) => {
        this.total = res.total;
        this.tableData = res.records;
      });
    },
    //新增分类
    creatoneOrg() {
      this.dialogVisibleorgtwo = !this.dialogVisibleorgtwo;
      let data = {
        questionnaireId: this.questionnaireId,
      };
      queryOptionStatistics(data).then((res) => {
        this.tableDatatongji = res.records;
        this.tableDatatongji.forEach((item, i) => {
          console.log(this.tableDatatongji[i].subjectType, 'oo');
          if (this.tableDatatongji[i].subjectType == 0) {
            this.titlename = '单选题';
          } else if (this.tableDatatongji[i].subjectType == 1) {
            this.titlename = '多选题';
          } else if (this.tableDatatongji[i].subjectType == 2) {
            this.titlename = '评分题';
          }
        });
      });
    },
    creatoneOrgone(v) {
      console.log(v, 'll');
      this.flagorg = true;
      this.orgSeqxia = v.goodsTypeId;
      this.dialogVisibleorgone = !this.dialogVisibleorgone;
    },
    //修改分类
    changeorg(v) {
      this.dialogVisibleorg = !this.dialogVisibleorg;
      let data = {
        uuid: v.uuid,
      };
      queryQuestionnaireInfoById(data).then((res) => {
        this.tableDatawenti = res.records;
      });
    },
    //确认添加
    confirmEditone() {
      //   if (
      //         this.ruleForm.tagUrl == "" ||
      //         this.ruleForm.tagUrl == null
      //     ) {
      //         this.$message.error("请上传图标");
      //         return;
      //     }
      //     if (this.ruleForm.picUrl == "" || this.ruleForm.picUrl == null) {
      //         this.$message.error("请上传图片");
      //         return;
      //     }
      let data = {
        goodsTypeName: this.ruleForm.goodsTypeName,
        isRelatedActivity: this.ruleForm.isRelatedActivity,
        sortNo: this.ruleForm.sortNo,
        tagUrl: this.ruleForm.tagUrl,
        picUrl: this.ruleForm.picUrl,
        isDisplay: this.ruleForm.isDisplay,
        displayForm: this.ruleForm.displayForm,
        goodsTypeId: this.ruleForm.goodsTypeId,
        upGoodsType: this.ruleForm.upGoodsType,
      };
      addGoodsType(data).then((res) => {
        this.$message({
          showClose: true,
          message: '添加成功',
          type: 'success',
        });
        this.dialogVisibleorg = !this.dialogVisibleorg;
        this.rolemanageone();
      });
    },
    //确定修改
    confirmEdittwo() {
      // if (
      //     this.ruleFormorg.tagUrl == "" ||
      //     this.ruleFormorg.tagUrl == null
      // ) {
      //     this.$message.error("请上传图标");
      //     return;
      // }
      // if (
      //     this.ruleFormorg.picUrl == "" ||
      //     this.ruleFormorg.picUrl == null
      // ) {
      //     this.$message.error("请上传图片");
      //     return;
      // }
      if (this.flagorg == false) {
        let dataone = {
          goodsTypeName: this.ruleFormorg.goodsTypeName,
          isRelatedActivity: this.ruleFormorg.isRelatedActivity,
          sortNo: this.ruleFormorg.sortNo,
          picUrl: this.ruleFormorg.picUrl,
          tagUrl: this.ruleFormorg.tagUrl,
          isDisplay: this.ruleFormorg.isDisplay,
          displayForm: this.ruleFormorg.displayForm,
          goodsTypeId: this.ruleFormorg.goodsTypeId,
        };
        addGoodsType(dataone).then((res) => {
          this.dialogVisibleorgone = !this.dialogVisibleorgone;
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success',
          });
          this.rolemanageone();
        });
      } else if (this.flagorg == true) {
        let data = {
          goodsTypeName: this.ruleFormorg.goodsTypeName,
          isRelatedActivity: this.ruleFormorg.isRelatedActivity,
          sortNo: this.ruleFormorg.sortNo,
          tagUrl: this.ruleFormorg.tagUrl,
          picUrl: this.ruleFormorg.picUrl,
          isDisplay: this.ruleFormorg.isDisplay,
          displayForm: this.ruleFormorg.displayForm,
          goodsTypeId: this.ruleFormorg.goodsTypeId,
          upGoodsType: this.orgSeqxia,
        };
        addGoodsType(data).then((res) => {
          this.$message({
            showClose: true,
            message: '添加成功',
            type: 'success',
          });
          this.dialogVisibleorgone = !this.dialogVisibleorgone;
          this.rolemanageone();
        });
      }
    },
    //停用启用
    updateStatus(goodsTypeId, status) {
      let data = {
        goodsTypeId: goodsTypeId,
        status: status,
      };
      addGoodsType(data).then((res) => {
        var msg = '';
        if (status == '1') {
          msg = '启用';
        } else if (status == '0') {
          msg = '停用';
        } else if (status == '2') {
          msg = '删除';
        }
        if (res.code == '1') {
          this.$message({
            showClose: true,
            message: msg + '成功',
            type: 'success',
          });
          this.rolemanageone();
        } else {
          this.$message.error(msg + '失败');
        }
      });
    },
    indexMethod(index) {
      let curpage = this.listQuery.current; //单前页码，具体看组件取值
      let limitpage = this.listQuery.size; //每页条数，具体是组件取值
      return index + 1 + (curpage - 1) * limitpage;
    },
    handledelete(v) {
      let data = {
        goodsTypeId: v.goodsTypeId,
      };
      this.$confirm('确认删除吗？').then((_) => {
        deleteGoodsType(qs.stringify(data)).then((res) => {
          this.$message({
            showClose: true,
            message: res.message,
            type: res.code == 0 ? 'success' : 'error',
          });
          this.rolemanageone();
        });
      });
    },
    add() {
      // this.dialogVisible = !this.dialogVisible;
      this.editflag = true;
    },
    edit(v) {
      console.log(v, 'kkdd');
      this.ruleForm.orgName = v.orgName;
      this.ruleForm.goodsTypeId = v.goodsTypeId;
      this.ruleForm.upOrgSeq = v.upOrgSeq;
      this.ruleForm.upOrgSeqName = v.upOrgSeqName;
      this.ruleForm.orgType = v.orgType;
      this.ruleForm.updateUser = v.updateUser;
      this.ruleForm.sortNo = v.sortNo;
      this.ruleForm.tagUrl = v.tagUrl;
      this.ruleForm.picUrl = v.picUrl;
      console.log(v, 'pp');
      // this.dialogVisible = !this.dialogVisible;
      this.editflag = false;
    },
    confirmEdit(v) {
      if (this.ruleForm.orgName == '' || this.ruleForm.orgName == null) {
        this.$message.error('请输入本级组织名称');
        return;
      }
      if (
        this.ruleForm.goodsTypeId == '' ||
        this.ruleForm.goodsTypeId == null
      ) {
        this.$message.error('请输入本级组织编码');
        return;
      }
      if (this.ruleForm.upOrgSeq == '' || this.ruleForm.upOrgSeq == null) {
        this.$message.error('请选择上级组织名称');
        return;
      }
      if (this.ruleForm.orgType == '' || this.ruleForm.orgType == null) {
        this.$message.error('请选择组织类型');
        return;
      }
      if (this.editflag) {
        //   var u1 = "u1";
        var userId = localStorage.getItem('userId');
        let data = {
          orgName: this.ruleForm.orgName,
          goodsTypeId: this.ruleForm.goodsTypeId,
          upOrgSeq: this.ruleForm.upOrgSeq,
          upOrgSeqName: this.ruleForm.upOrgSeqName,
          sortNo: this.ruleForm.sortNo,
          picUrl: this.ruleForm.picUrl,
          tagUrl: this.ruleForm.tagUrl,
          updateUser: this.ruleForm.updateUser,
        };
        addGoodsType(data).then((res) => {
          this.dialogVisible = !this.dialogVisible;
          this.$message({
            showClose: true,
            message: '添加成功',
            type: 'success',
          });
          this.rolemanageone();
        });
      } else {
        //var u1 = "u1";
        var userId = localStorage.getItem('userId');
        let data = {
          orgName: this.ruleForm.orgName,
          goodsTypeId: this.ruleForm.goodsTypeId,
          picUrl: this.ruleForm.picUrl,
          tagUrl: this.ruleForm.tagUrl,
          updateUser: this.ruleForm.updateUser,
        };
        updaterole(data).then((res) => {
          this.dialogVisible = !this.dialogVisible;
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success',
          });
          this.rolemanageone();
        });
      }
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.rolemanageone();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.rolemanageone();
    },

    descInput() {
      this.txtVal = this.updateDiseaseForm.memo.length;
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleImg = true;
    },
    upLoadPicone(file, fileList) {
      this.imgListone = [];
      this.ruleForm.tagUrl = file.result;
      this.ruleFormorg.tagUrl = file.result;
    },
    handleImgChangeone(file, fileList) {
      if (file.response) {
        this.imgListone.push({
          url: file.response.result,
          status: 'finished',
        });
      }
    },
    upLoadPictwo(file, fileList) {
      this.imgListtwo = [];
      this.ruleForm.picUrl = file.result;
      this.ruleFormorg.picUrl = file.result;
    },
    handleImgChangetwo(file, fileList) {
      if (file.response) {
        this.imgListtwo.push({
          url: file.response.result,
          status: 'finished',
        });
      }
    },
    checkSortNo(val, type) {
      // 值，符号
      if (val === null || val === undefined || val === '') {
        return this.total + 1;
      } else {
        var aaa = Number(this.total + 1);
        if (Number(val) < aaa) {
          this.$confirm(
            '此操作将排序小于推荐值' + aaa + ', 是否继续?',
            '提示',
            {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            }
          )
            .then(() => {
              return (
                (this.ruleForm.sortNo = val), (this.ruleFormorg.sortNo = val)
              );
            })
            .catch(() => {
              return (
                (this.ruleForm.sortNo = aaa), (this.ruleFormorg.sortNo = aaa)
              );
            });
        } else {
          return val;
        }
      }
    },
    handleExceed(file, fileList6) {
      this.$message.error(`图片最多上传1张`);
    },
    handleSort(val) {
      let sortModel = '';
      if (val.order === 'ascending') {
        sortModel = 'ASC';
        if (val.prop == 'orderMoney') {
          this.formInline.moneySort = 1;
          this.formInline.satisfactionSort = '';
          this.search();
        }
        if (val.prop == 'satisfaction') {
          this.formInline.moneySort = '';
          this.formInline.satisfactionSort = 1;
          this.search();
        }
      } else if (val.order === 'descending') {
        sortModel = 'DESC';
        if (val.prop == 'orderMoney') {
          this.formInline.moneySort = 2;
          this.formInline.satisfactionSort = '';
          this.search();
        }
        if (val.prop == 'satisfaction') {
          this.formInline.moneySort = '';
          this.formInline.satisfactionSort = 2;
          this.search();
        }
      }
    },
  },
};
</script>
<style lang="less" scoped>
.toptitle {
  border: 1px solid #e0e0e0;
  border-bottom: 2px solid #188097;
  background: #f5f5f5;
  line-height: 35px;
  margin-bottom: 10px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: bold;
}

.el-form-item .el-select {
  width: 100%;
}
</style>
